<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script src="/webjars/axios/0.19.0/dist/axios.js" type="text/javascript"></script>
</head>
<body>
<div id="vuebox">
    <div class="container" style="margin-top: 50px">


            <h1>学员信息列表</h1>
        <button type="button" @click="addStudent()">添加学员信息</button>
        <br/>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>编号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>电话</th>
                <th>email</th>
                <th>班级</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="item in studentList">
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.gender}}</td>
                <td>{{item.age}}</td>
                <td>{{item.telephone}}</td>
                <td>{{item.email}}</td>
                <td>
                    <p v-if="item.classid==1">一班</p>
                    <p v-if="item.classid==2">二班</p>
                    <p v-if="item.classid==3">三班</p>
                </td>
            </tr>
            </tbody>
        </table>
        <br/>
    </div>

    <!--模态框-->
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" type="button"  @click="hideModal(),clearForm()">&times;</button>
                    <div class="modal-title">
                        添加学员信息
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label for="id" class="col-sm-2 control-label">编号:</label>
                            <div class="col-sm-10">
                                <input v-model="add_student.id" id="id" type="text" class="form-control" placeholder="请输入商品编号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">姓名:</label>
                            <div class="col-sm-10">
                                <input v-model="add_student.name" id="name" type="text" class="form-control" placeholder="请输入名称">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="age" class="col-sm-2 control-label">年龄:</label>
                            <div class="col-sm-10">
                                <input v-model="add_student.age" id="age" type="text" class="form-control" placeholder="请输入商品数量">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="gender" class="col-sm-2 control-label">性别:</label>
                            <div class="col-sm-10">
                                <input v-model="add_student.price" id="gender" type="gender" class="form-control" placeholder="请输入商品价格"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="telephone" class="col-sm-2 control-label">电话:</label>
                            <div class="col-sm-10">
                                <input v-model="add_student.telephone" id="telephone" type="text" class="form-control" placeholder="请输入商品数量">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="email" class="col-sm-2 control-label">email:</label>
                            <div class="col-sm-10">
                                <input v-model="add_student.email" id="email" type="text" class="form-control" placeholder="请输入商品数量">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="classid">班级：</label>
                            <select id="classid" class="form-control" v-model="add_student.classid">
                                <option  value="1">一班</option>
                                <option value="2">二班</option>
                                <option value="3">三班</option>
                            </select>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" @click="hideModal(),clearForm()">关闭</button>
                    <button class="btn btn-primary" @click="saveBook()">保存</button>
                </div>
            </div>
        </div>
    </div>


</div>




</body>
<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            studentList:{},
            delResult:{},
            add_student:{id:'',name:'',age:'',gender:'',telephone:'',email:'',classid:''},
        },methods:{
            select:function(){
                axios.get("/select").then(
                    res=>{this.studentList=res.data});
            },
            //    添加图书,显示模态框
            addStudent:function () {
                $('#mymodal').modal('show');
            },
            //    隐藏模态框
            hideModal:function () {
                $("#mymodal").modal('hide');
                //调用清空模态框的方法
                this.clearForm();
            },
            //    清空模态框内容
            clearForm:function () {
                $("#id").val();
                $("#name").val('');
                $("#age").val('');
                $("#gender").val('');
                $("#telephone").val("");
                $("#email").val('');
                $("#classid").val("");
            },
            //新增图书信息
            saveBook:function () {
                axios.post("/add",this.add_student).then(res=>{
                    this.delResult=res.data
                    this.clearForm();
                    this.hideModal();
                    this.select();
                })
            }
        },
        mounted(){
            this.select();
        },

    })
</script>
</html>